﻿using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Linq;
using System.Text;

namespace GeFIN
{
    public class Connection
    {
        //atributos
            SqlConnection connection;
            SqlCommand command;
            SqlDataReader dtReader; 

        //construtor
            public Connection()
            {
                connection = new SqlConnection();
                string strConnection = "Data Source = localhost; Initial Catalog = GeFINSystem; Integrated Security = SSPI";
                connection.ConnectionString = strConnection;
                connection.Open();
            }

        //metodos

            public void consult(string commandString)
            {
                command = new SqlCommand(commandString, connection);
                dtReader = command.ExecuteReader();
            }

            public void finishConsult()
            {
                dtReader.Close();
            }

            public bool readConsult()
            {
                return dtReader.Read();
            }

            public string getResultString(int index)
            {
                return dtReader.GetString(index);
            }

            public void close()
            {
                connection.Close();
            }
    }
}
